package de.koller.planet2D.container;

import de.koller.oceanFramework.OceanException;
import de.koller.oceanFramework.math.Vec;
import de.koller.planet2D.PNode;
import de.koller.planet2D.rcom.AddPNode;

public class RenderObj extends PNode {
	
	public final Vec position = new Vec();
	public final Vec size = new Vec( 1, 1 );
	public double rotation = 0;
	
	public boolean deletable = true;
	private TextureEntity textureEntity = null;
	
	@Override
	protected void init() {
		super.init();
		
		proot.renderContainer.renderObjects.add( this );
	}

	@Override
	protected void release() {
		super.release();
		
		proot.renderContainer.renderObjects.remove( this );
	}
	
	public boolean inSelect( double x, double y, double r ) {
		if( r*r > ((position.getX()-x)*(position.getX()-x)) + ((position.getY()-y)*(position.getY()-y)) )
			return true;
		
		return false;
	}

	public void setTextured() {
		if( textureEntity != null )
			throw new OceanException( "Already textured!" );
		textureEntity = new TextureEntity();
		proot.call( new AddPNode( this, textureEntity ) );
	}
	
	public TextureEntity getTextureEntity() {
		return textureEntity;
	}
	
}
